<?php
namespace app\common\model;

use think\Model;
use think\Session;

class Users extends Model
{
    protected $insert = ['auid'];
    protected $wx_user;

    protected function initialize(){
        parent::initialize();
        $this->wx_user = Session::get('wechat_info');
    }

    protected static function init(){
        parent::init();

        self::event('after_insert', function ($data){
            // file_put_contents('./requestMsg.log',time().'用户粉丝表新增了数据=1=:'."\n", FILE_APPEND);
        });

        self::event('after_update', function ($data){
            // file_put_contents('./requestMsg.log',time().'用户粉丝表更新了数据=1=:'."\n", FILE_APPEND);
        });

    }

    /**
     * 创建时间
     * @return bool|string
     */
    // protected function setCreateTimeAttr()
    // {
    //     return date('Y-m-d H:i:s');
    // }

    protected function setAuidAttr($value = ''){
        if(!empty($value)) return $value;
        return $this->wx_user['id'];
    }

    protected function setTagidListAttr($value){
        return serialize($value);
    }

    protected function getTagidListAttr($value){
        return unserialize($value);
    }
}